package com.demo2do.wechatmcs.entity;

import org.apache.commons.lang3.StringUtils;

import com.demo2do.core.utils.Alias;

/**
 * 
 * @author mohanlan
 *
 */
@Alias("authorizationScope")
public enum AuthScope {
    
    BASE("snsapi_base"),
    
    USERINFO("snsapi_userinfo"),
    
    LOGIN("snsapi_login");
    
    private String scope;
    
    /**
     * @param scope
     */
    private AuthScope(String scope) {
        this.scope = scope;
    }
    
    /**
     * @return the scope
     */
    public String getScope() {
        return scope;
    }
    
    /**
     * 
     * @param scope
     * @return
     */
    public static AuthScope scopeOf(String scope) {
        for (AuthScope authScope : AuthScope.values()) {
            if (StringUtils.equalsIgnoreCase(authScope.getScope(), scope)) {
                return authScope;
            }
        }
        return null;
    }
    
    /**
     * 
     * @param scope
     * @return
     */
    public static boolean isWebAuth(String scope) {
        AuthScope authScope = AuthScope.scopeOf(scope);
        return authScope != null && (AuthScope.BASE.equals(authScope) || AuthScope.USERINFO.equals(authScope));
    }
    
    /**
     * 
     * @param scope
     * @return
     */
    public static boolean isUserInfo(AuthScope scope) {
        return scope.equals(AuthScope.USERINFO);
    }
}
